//
//  TrimFromTo2.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/21.
//

import SwiftUI

struct TrimFromTo2: View {
  var body: some View {
    TrimmedShapeView()
  }
}

#Preview {
  TrimFromTo2()
}

struct CustomShape: Shape {
  func path(in rect: CGRect) -> Path {
    var path = Path()
    path.move(to: CGPoint(x: rect.midX, y: rect.minY))
    path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
    path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
    path.closeSubpath()
    return path
  }
}

struct TrimmedShapeView: View {
  var body: some View {
    CustomShape()
      .trim(from: 0.0, to: 0.8)
      .stroke(Color.blue, lineWidth: 4)
      .frame(width: 200, height: 200)
      .background(.yellow)

  }
}
